<?php 
class contact extends CI_controller{

	function __construct(){
		parent::__construct();

		$this->load->helper('bara_helper');
		$this->load->library('bara_lib');

		$this->load->library('recaptcha');

		$this->load->model('modul/contact_model');

		$this->load->model('modul/model_menu');
		
		$this->load->model('modul/about_model');
		$this->load->model('modul/article_model');
		$this->load->model('modul/sosmed_model');
	}

	function index(){

		$data['text_home'] = "Home";
		$data['text_title'] = "Contact Us";

		$this->recaptcha->recaptcha_check_answer();

		if ($this->input->post() && $this->recaptcha->getIsValid()) {
			
			$date = get_date_time();

			$data_contact = array(
				'date_update' => $date,
				'name' => $this->input->post('name'),
				'email' => $this->input->post('email'),
				'phone' =>$this->input->post('phone'),
				'message' =>$this->input->post('message')
				);

			$id_menu = $this->db->insert('contact', $data_contact);

			$data['benar'] = "<div class='alert success'><i class='icon-success'></i> This is a Success Message! <span class='alert-close fa-times'></span></div>";
        } else if ($this->input->post() && !$this->recaptcha->getIsValid()) {
        	$data['benar'] = "<div class='alert error'><i class='icon-error'></i> An Error Message! <span class='alert-close fa-times'></span></div>";
        } else {
        	$data['benar'] = "";
        }

        $data['recaptcha_html'] = $this->recaptcha->recaptcha_get_html();

        $data['gets_contact'] = $this->contact_model->get_contact('contact_us',$this->bara_lib->language());
		$data['gets_numbers'] = $this->contact_model->get_contact('numbers',$this->bara_lib->language());
		$data['gets_address'] = $this->contact_model->get_contact('address',$this->bara_lib->language());
		$data['gets_maps'] = $this->contact_model->get_contact('maps',$this->bara_lib->language());

		$data['content'] = 'frontend/'. $this->bara_lib->theme() .'/contact/contact';

		//menu
		$data['get_menus'] = $this->model_menu->get_menu($this->bara_lib->language());

		// sosmed
		$data['gets_facebook'] = $this->sosmed_model->get_sosmed('facebook');
		$data['gets_twitter'] = $this->sosmed_model->get_sosmed('twitter');
		$data['gets_sosmed'] = $this->sosmed_model->get_sosmed_all();

		//footer
		$data['gets_about_footer'] = $this->about_model->get_about('about_us',$this->bara_lib->language());
		$data['get_articles_footer'] = $this->article_model->get_article($this->bara_lib->language(),3,0);
		//end footer

		$data['head'] = 'layout/'. $this->bara_lib->theme() .'/head';
		$data['menu'] = 'layout/'. $this->bara_lib->theme() .'/menu';
		$data['footer'] = 'layout/'. $this->bara_lib->theme() .'/footer';
		$this->load->view('layout/'. $this->bara_lib->theme() .'/inner', $data);	
	}

}
?>